<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/2
 * Time: 17:42
 */

namespace App\Http\Controllers;


use Illuminate\Http\Request;

class PublicController extends  Controller
{

    public  function index()
    {
        return view('public.home');
    }

    public function Home(){
        return view('public.index');
    }

    /**
     * 文件上传
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function UploadImg(Request $request)
    {
        $file = $request->file('file');


        $user = $request->getSession('user')->get('user');
            if(!$file -> isValid()){
                return response(['msg'=>'文件上传出错'],440);
            }
            // 获取后缀名
            $ext = $file->extension();
            // 新文件名
            $saveName =time().rand(1111,9999).".".$ext;
            $path = $file->storeAs($user['account'],$saveName,'local') ;

            $path =  'http://'.$request->getHost().':'.$request->getPort().'/upload/'.$path;
        return response()->json(["code"=>1,"msg"=>$path]);
    }

    public function DeleteImg(Request $request)
    {
        $url = $request->get('server_url');

        return response()->json(['code'=>1],200);

    }
}